import React, { PureComponent } from "react";
import { connect } from "dva";
import router from 'umi/router';
import { Card, Table, Icon } from "antd";
import styles from "./Dashboard.less";


@connect(({ dashboard, loading }) => ({
  warnMonitor:dashboard.chartsData.warnMonitor,
  loading: loading.models.dashboard,
}))
export default class Dashboard extends PureComponent {
  constructor(props) {
    super(props);

  }

  componentDidMount() {

  }

  // 告警详情
  handleWarnInfo = (id)=>{
    const { dispatch } = this.props;
    // const { formValues, currentPage} = this.state;
    router.push({ pathname:`/alarm/currentalarm/${id}`});
  }

  render() {
    const {warnMonitor,loading } = this.props;

    const columns = [{
      dataIndex: 'warnCode',
      render: text=> <span><Icon type="warning" style={{color:'#f22',marginRight:10}}/>{text}</span>
    },{
      dataIndex: 'warnCon',
      align:'right',
      render: text=> <span>{text}</span>
    }];


    return (
      <Card
        bordered={false}
        bodyStyle={{padding:'0'}}
        hoverable={true}
        style={{marginTop:0}}

      >
        <Table className={styles.tablechartnormal}
               columns={columns}
               dataSource={warnMonitor}
               pagination={false}
               size="small"
               showHeader={false}
               rowKey={"warnId"}
               loading={loading}
               onRow={(record) => {
                 return {
                   onClick: () => {
                     // 点击行
                     this.handleWarnInfo(record.warnId)
                   },
                 };
               }}
        />
      </Card>
    );
  }
}
